package com.woniu.service;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 杨光 微信号:tolryg
 * @time 15:38
 */

@Service
public class CellphoneCodeService {


    @RabbitListener(queues = {"woniu84_register_code_queue"})
    public void sendCellphoneCode(String cellphoneCode){

        System.out.println("cellphoneCode = " + cellphoneCode);
        String[] split = cellphoneCode.split("_");
        String cellPhone = split[0];
        String code = split[1];

        //连接阿里云短信服务，发验证码
/*
        Map<String,Object> map = new HashMap<>();
        map.put("code",code);//验证码

        DefaultProfile profile =
                DefaultProfile.getProfile("default", "自己的accesskeyId",
                        "自己的accessKeySecret");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        //request.setProtocol(ProtocolType.HTTPS);
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");

        request.putQueryParameter("PhoneNumbers", cellPhone);   //手机号
        request.putQueryParameter("SignName", 自己申请的签名);    //签名名称
        request.putQueryParameter("TemplateCode", 自己申请的模板code);  //模板名称
        request.putQueryParameter("TemplateParam", JSONObject.toJSONString(map));  //验证码转换json数据

        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
*/
    }
}
